from grammar import Grammar

class ParseNode:
    def __init__(self, type):
        self.type = type
        self.children = []
        self.terminal = None

class Parser:
    def __init__(self, grammarFilename):
        self.grammarFilename = grammarFilename
        self.grammar = Grammar(grammarFilename)
        
    def parse(self, lexer):
        assert "start" in self.grammar.rules, "no start symbol in grammar %s" % self.grammarFilename
        
        return self.matchRule("start",self.grammar.rules["start"],lexer)
    
    def matchRule(self, ruleName, rule, lexer):
        node = ParseNode(ruleName)
